package com.controller;

import com.dto.DTO;
import com.entity.News;
import com.entity.Newsrecord;
import com.service.NewsService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
@CrossOrigin

@Controller //@Controller注解是用spring容器生成 对象 默认对象名 newsController
@RequestMapping("/newsController") //@RequestMapping 用户请求查找该资源使用的名字 网名 默认  /newsController
public class NewsController {
	@Resource
	NewsService newsService;
	@RequestMapping("/getAllNews")
	@ResponseBody //把方法的返回值按json转换之后 输出到浏览器
    public DTO<News> getAllNews() throws Exception {
    	System.out.println("查询全部新闻");
		return newsService.getAllNewss();
    }

	@RequestMapping("/deleteNewsBynId/{nId}")
	@ResponseBody
    public DTO<News> deleteNewsBynId(@PathVariable("nId") String nId) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
    	System.out.println(nId+"删除新闻");
    	return newsService.deleteNewsBynId(nId);
    }

//	@RequestMapping("/getNewsByPage")
//	@ResponseBody
//	@SystemLog(module = "新闻管理",methods = "分页查询新闻")
//	public DTO<News> getNewsByPage(PageInfo pageInfo){//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
//		System.out.println("分页新闻");
//		return newsService.getNewsByPage(PageInfo pageInfo);
//	}

	@RequestMapping("/getNewsByIdWithAnos/{nId}")
	@ResponseBody
	public DTO<News> getNewsByIdWithAnos(@PathVariable("nId") String nId) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询新闻附上管理员");
		return newsService.getNewsByIdWithAnos(nId);
	}

	@RequestMapping("/getNewsByIdWithAnoandmembers/{nId}")
	@ResponseBody
	public DTO<News> getNewsByIdWithAnoandmembers(@PathVariable("nId") String nId) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("查询新闻附上管理员和社团");
		return newsService.getNewsByIdWithAnoandmembers(nId);
	}

	@RequestMapping("/addNews")
	@ResponseBody
	public DTO<News> addNews(@RequestBody News news) throws Exception {//如何从页面传入参数到方法 用这个注解绑定变量@PathVariable
		System.out.println("增加新闻");
		System.out.println(news);
		return newsService.addNews(news);
	}


}
